/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include "ScanMethod.h"

class ScanMethodPassive : public ScanMethod
{
private:
	BYTE rBuffer1[18];
	BYTE rBuffer2[6];
	BYTE rBuffer3[256];

protected:
	bool dataProcessed;

	virtual int InternalInit(void);
	virtual int InternalExecute(void);

	// ARP
	virtual void ProcessArpAny(BYTE*, int);

	// ICMP
//	virtual void ProcessEchoReplyEx(BYTE*, int, BYTE*);
//	virtual void ProcessHostUnreacheable(BYTE*, int);
//	virtual void ProcessProtocolUnreacheable(BYTE*, int);
//	virtual void ProcessPortUnreacheable(BYTE*, int);
	virtual void ProcessIcmpAny(BYTE*, int, BYTE*);

	// IGMP
	virtual void ProcessIgmp(BYTE*, int, BYTE*);

	// TCP
	virtual void ProcessTcp(BYTE*, int, BYTE*);

	// UDP
	virtual void ProcessUdpEx(BYTE*, int, BYTE*);
		void ProcessDnsResponse(BYTE*, BYTE*, BYTE*, int);
			bool ExtractAddressFromResponse(BYTE*, int, DWORD*, int*);
			bool ExtractNameFromResponse(BYTE*, int, int*);
			void FormatName(BYTE*, int);
		void ProcessNTPResponse(BYTE*, BYTE*, BYTE*, int);
		void ProcessSSDP(BYTE*, BYTE*, BYTE*, int);

	// IPv4 Other
	virtual void ProcessOtherIpPacket(BYTE*, int, BYTE*);

	// ICMPv6
//	virtual void ProcessDestinationUnreachable6(BYTE*, int, BYTE*);
//	virtual void ProcessPortUnreachable6(BYTE*, int, BYTE*);
//	virtual void ProcessErrHeaderField(BYTE*, int, BYTE*, BYTE*);
//	virtual void ProcessUnkNextHeader(BYTE*, int, BYTE*, BYTE*);
//	virtual void ProcessUnkIPv6Option(BYTE*, int, BYTE*, BYTE*);
	virtual void ProcessEchoReply6(BYTE*, int, BYTE*, BYTE*);
	virtual void ProcessMulticastListenerReport(BYTE*, int, BYTE*, BYTE*);
	virtual void ProcessRouterAdvertisement(BYTE*, int, BYTE*, BYTE*);
	virtual void ProcessNeighborAdvertisement(BYTE*, int, BYTE*, BYTE*);
	virtual void ProcessIcmp6Any(BYTE*, int, BYTE*, BYTE*);

	// TCPv6
	virtual void ProcessTcp6(BYTE*, int, BYTE*, BYTE*);

	// UDPv6
	virtual void ProcessUdp6(BYTE*, int, BYTE*, BYTE*);

	// IPv6 Other
	virtual void ProcessOther6Packet(BYTE*, int, BYTE*, BYTE*);

	// IPX/SPX
	virtual void ProcessIPXorSPX(BYTE*, int, BYTE*);

	// STP
	virtual void ProcessSTP(BYTE*, int, BYTE*);
	virtual void ProcessGVRP(BYTE*, int, BYTE*);
	virtual void ProcessGMRP(BYTE*, int, BYTE*);

	// Cisco CDP si DTP
	virtual void ProcessCDP(BYTE*, int, BYTE*);
	virtual void ProcessDTP(BYTE*, int, BYTE*);

	// Ethernet Other
	virtual void ProcessOtherEthernetPacket(WORD, BYTE*, int, BYTE*);

	MFullAddress addrX;
	MMachineInfo machX;
	MPortInfo    portX;
	MIGMPPacket  igmpX;
	MGxRPPacket  gxrpX;
	MSTPPacket   mstpX;
	MCDPPacket   mcdpX;
	MDTPPacket   mdtpX;
	void AddMachine(BYTE*, BYTE*);
	void AddMachineAndPort(BYTE*, BYTE*, WORD, WorkMethodType);
	void AddMachineAndDnsName(char*, DWORD, DWORD, WORD);
	void AddMachineSSDP(BYTE*, BYTE*);
	void AddMachine6(BYTE*, BYTE*);
	void AddMachine6AndPort(BYTE*, BYTE*, WORD, WorkMethodType);
	void AddMachineIPX(BYTE*, BYTE*);
	void AddMachineIGMP(BYTE*, BYTE*, BYTE, DWORD, BYTE);
	void AddMachineSTP(BYTE*);
	void AddMachineGxRP(BYTE*);
	void AddMachineCDP(BYTE*);
	void AddMachineDTP(BYTE*);

public:
	ScanMethodPassive(void);
	~ScanMethodPassive(void);
};
